package com.itheima.Listtest;

import java.util.ArrayList;

public class listTest8 {
    public static void main(String[] args) {
        //1.创建集合对象
        ArrayList<Phone> list = new ArrayList<>();

        //2.创建对象
        Phone p1 = new Phone("iphoneX", 8888);
        Phone p2 = new Phone("小米", 1000);
        Phone p3 = new Phone("锤子", 2999);

        //3.添加数据
        list.add(p1);
        list.add(p2);
        list.add(p3);

        ArrayList<Phone> phoneInfo = getPhoneInfo(list);
        for (int i = 0; i < phoneInfo.size(); i++) {
            System.out.println(phoneInfo.get(i).getBrand()+" "+phoneInfo.get(i).getPrice());
        }
    }

    public static ArrayList<Phone> getPhoneInfo(ArrayList<Phone> list){
        //定义一个集合用于存储价格低于3000的手机
        ArrayList<Phone> resultList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getPrice()<3000){
                resultList.add(list.get(i));
            }
        }

        return resultList;
    }

}
